package com.mycompany.myapp.domain;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;

import java.io.Serializable;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.Set;

/**
 * A Commodity.
 */
@Entity
@Table(name = "commodity")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Commodity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "cname")
    private String cname;

    @Column(name = "star")
    private Integer star;

    @Column(name = "price")
    private Double price;

    @Column(name = "img_url")
    private String imgUrl;

    @Column(name = "detail")
    private String detail;

    @Column(name = "model")
    private String model;

    @Column(name = "create_time")
    private ZonedDateTime createTime;

    @Column(name = "count")
    private Integer count;

    @Column(name = "fashion")
    private String fashion;

    @Column(name = "quality")
    private String quality;

    @Column(name = "brand")
    private String brand;

    @Column(name = "status")
    private String status;

    @OneToMany(mappedBy = "commodity")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<Comment> comments = new HashSet<>();

    @OneToMany(mappedBy = "commodity")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<Collection> collections = new HashSet<>();

    @OneToMany(mappedBy = "commodity")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<CartItem> cartItems = new HashSet<>();

    @OneToMany(mappedBy = "commodity")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<OrderItem> orderItems = new HashSet<>();

    // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCname() {
        return cname;
    }

    public Commodity cname(String cname) {
        this.cname = cname;
        return this;
    }

    public void setCname(String cname) {
        this.cname = cname;
    }

    public Integer getStar() {
        return star;
    }

    public Commodity star(Integer star) {
        this.star = star;
        return this;
    }

    public void setStar(Integer star) {
        this.star = star;
    }

    public Double getPrice() {
        return price;
    }

    public Commodity price(Double price) {
        this.price = price;
        return this;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public Commodity imgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
        return this;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public String getDetail() {
        return detail;
    }

    public Commodity detail(String detail) {
        this.detail = detail;
        return this;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getModel() {
        return model;
    }

    public Commodity model(String model) {
        this.model = model;
        return this;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public ZonedDateTime getCreateTime() {
        return createTime;
    }

    public Commodity createTime(ZonedDateTime createTime) {
        this.createTime = createTime;
        return this;
    }

    public void setCreateTime(ZonedDateTime createTime) {
        this.createTime = createTime;
    }

    public Integer getCount() {
        return count;
    }

    public Commodity count(Integer count) {
        this.count = count;
        return this;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public String getFashion() {
        return fashion;
    }

    public Commodity fashion(String fashion) {
        this.fashion = fashion;
        return this;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void setFashion(String fashion) {
        this.fashion = fashion;
    }

    public String getQuality() {
        return quality;
    }

    public Commodity quality(String quality) {
        this.quality = quality;
        return this;
    }

    public void setQuality(String quality) {
        this.quality = quality;
    }

    public String getBrand() {
        return brand;
    }

    public Commodity brand(String brand) {
        this.brand = brand;
        return this;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public Set<Comment> getComments() {
        return comments;
    }

    public Commodity comments(Set<Comment> comments) {
        this.comments = comments;
        return this;
    }

    public Commodity addComment(Comment comment) {
        this.comments.add(comment);
        comment.setCommodity(this);
        return this;
    }

    public Commodity removeComment(Comment comment) {
        this.comments.remove(comment);
        comment.setCommodity(null);
        return this;
    }

    public void setComments(Set<Comment> comments) {
        this.comments = comments;
    }

    public Set<Collection> getCollections() {
        return collections;
    }

    public Commodity collections(Set<Collection> collections) {
        this.collections = collections;
        return this;
    }

    public Commodity addCollection(Collection collection) {
        this.collections.add(collection);
        collection.setCommodity(this);
        return this;
    }

    public Commodity removeCollection(Collection collection) {
        this.collections.remove(collection);
        collection.setCommodity(null);
        return this;
    }

    public void setCollections(Set<Collection> collections) {
        this.collections = collections;
    }

    public Set<CartItem> getCartItems() {
        return cartItems;
    }

    public Commodity cartItems(Set<CartItem> cartItems) {
        this.cartItems = cartItems;
        return this;
    }

    public Commodity addCartItem(CartItem cartItem) {
        this.cartItems.add(cartItem);
        cartItem.setCommodity(this);
        return this;
    }

    public Commodity removeCartItem(CartItem cartItem) {
        this.cartItems.remove(cartItem);
        cartItem.setCommodity(null);
        return this;
    }

    public void setCartItems(Set<CartItem> cartItems) {
        this.cartItems = cartItems;
    }

    public Set<OrderItem> getOrderItems() {
        return orderItems;
    }

    public Commodity orderItems(Set<OrderItem> orderItems) {
        this.orderItems = orderItems;
        return this;
    }

    public Commodity addOrderItem(OrderItem orderItem) {
        this.orderItems.add(orderItem);
        orderItem.setCommodity(this);
        return this;
    }

    public Commodity removeOrderItem(OrderItem orderItem) {
        this.orderItems.remove(orderItem);
        orderItem.setCommodity(null);
        return this;
    }

    public void setOrderItems(Set<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }
    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Commodity)) {
            return false;
        }
        return id != null && id.equals(((Commodity) o).id);
    }

    @Override
    public int hashCode() {
        return 31;
    }

    @Override
    public String toString() {
        return "Commodity{" +
            "id=" + id +
            ", cname='" + cname + '\'' +
            ", star=" + star +
            ", price=" + price +
            ", imgUrl='" + imgUrl + '\'' +
            ", detail='" + detail + '\'' +
            ", model='" + model + '\'' +
            ", createTime=" + createTime +
            ", count=" + count +
            ", fashion='" + fashion + '\'' +
            ", quality='" + quality + '\'' +
            ", brand='" + brand + '\'' +
            ", status='" + status + '\'' +
            '}';
    }
}
